package com.twu.biblioteca.Actions;

import com.twu.biblioteca.Interfaces.MenuItems;
import com.twu.biblioteca.Models.Book;
import com.twu.biblioteca.Models.BookCollection;

import java.io.IOException;

    public class BookReserver implements MenuItems
    {
        private BookCollection bookCollection;

        public BookReserver(BookCollection bookCollection)
        {
            this.bookCollection = bookCollection;
        }

        public void takeAction() throws IOException
        {
            System.out.println("Which book would you like to reserve?");
            InputReader inputReader = new InputReader();
            String userInput = inputReader.readUserInput();
            reserveBook(userInput);
        }

        public boolean reserveBook(String title)
        {
            Boolean reserved = false;
            for (Book book : bookCollection.returnAvailableBookList()) {
                if (title.equals(book.getTitle()))
                {
                    book.reserveBook();
                    reserved = true;
                    System.out.println("Thank you! Enjoy the book");
                    break;
                }
            }
            if(!reserved)
            {
                System.out.println("Sorry we don't have that book yet.");
            }
            return reserved;
        }
    }
